package com.borrower.action;

import com.borrower.service.BorrowerServiceImpl;
import com.google.gson.Gson;
import com.pojo.QueryBookBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class AjaxReturnBookInfoAction extends Action{
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String bookName = request.getParameter("bookName");

        System.out.println(bookName);

        PrintWriter out = response.getWriter();

        List<QueryBookBean> list=new ArrayList<>();

        BorrowerServiceImpl borService = new BorrowerServiceImpl();

        list=borService.queryBookInfoByName(bookName);

        Gson gson = new Gson();

        String jsonStr = gson.toJson(list);

        out.print(jsonStr);





    }
}
